﻿
@{
    ViewBag.Title = "GetHospitalAdmin";
    Layout = "~/Views/Shared/_HospitalAdminLayout.cshtml";
    
}
@section Header{
    <link href="~/Asset/font-awesome-4.6.3/css/font-awesome.min.css" rel="stylesheet" />
    <script src="~/Asset/esimakin-twbs-pagination/jquery.twbsPagination.min.js"></script>
}
<script>
    $(document).ready(function () {
        $.ajax({
            url: '/Hospital/GetHosAdmin',
            type: 'post',
            success: function (d) {
                $("#mytbody").empty();
                $(d).each(function (i, obj) {
                    var d1 = '<tr><td>' + obj.Id + '</td><td>' + obj.Uname + '</td><td>' + obj.Pwd + '</td><td>' + obj.Hname + '</td> <td style="width:10%;"><div class="btn-group"><a href="#" class="btn btn-default btn-sm">管理</a> <a href="#" type="button" class="btn btn-default btn-sm dropdown-toggle" data-toggle="dropdown" aria-expanded="false"><span class="caret"></span> </a><ul class="dropdown-menu"><li><a class="hospital_edit" href="#" data-id="'+obj.Id+'">编辑</a></li><li><a href="#" onclick="Dele_show('+obj.Id+')">删除</a></li> </ul></div></td></tr>';
                    $("#mytbody").append(d1);
                })
            }
        })
    })
    //绑定下拉框的医院名称
    $(document).ready(function () {
        $.ajax({
            url: '/Hospital/GetAllHospital',
            type: 'post',
            success: function (d) {
                $("#select_show").empty();
                $(d).each(function (i, obj) {
                    var d1 = ' <option value='+obj.Id+'>'+obj.Name+'</option>';
                    $("#select_show").append(d1);
                })
            }
        })
    });
    //注册用户
    $(function () {
        $("#btn_add_hospital").click(function () {
            var name = $.trim($("#Name").val());
            var pwd = $.trim($("#Password").val());
            var id = $("#select_show").val();
            if (name == "") {
                alert("输入的账号有误");
                return 0;
            }
            if (pwd == "") {
                alert("输入的密码有误");
                return 0;
            }
            $.ajax({
                type: "post",
                url: "/Hospital/Adduser",
                data: {
                    id: id,
                    name: name,
                    pwd: pwd
                },
                success: function (d) {
                    if (d > 0) {
                        alert("注册成功");
                        location.href = "/Hospital/GetHospitalAdmin";
                    }
                    else {
                        alert("注册失败");
                    }
                }
            })
        })
    })
 
    function Dele_show(id)
    {
       if(confirm("确认要删除吗？"))
       {
           $.ajax({
               type:"get",
               url: "/Hospital/DeleteUser",
               data:{
                 id:id
               },
               success:function(d){
               if(d>0)
               {
                  alert("删除成功");
                  location.href = "/Hospital/GetHospitalAdmin";
                
               }
               else
               {
                  alert("删除失败");
               }
               }
           })
       }
    }
</script>



<div class="content">
    <div class="row">
        <div class="col-md-2">
            <div class="list-group">
                @*<a href="@Url.Action("Hospital", "Admin")" class="list-group-item">医院管理</a>
                <a href="@Url.Action("GetHospitalAdmin", "Admin")" class="list-group-item ">医院管理员管理</a>
                <a href="@Url.Action("GetQueAdmin", "Admin")" class="list-group-item">问答管理员管理</a>*@ 
                <a href="@Url.Action("Index", "Hospital")" class="list-group-item">回到首页</a>
            </div>
        </div>
        <div class="modal fade" id="modal_add_user" tabindex="-1" role="dialog" aria-labelledby="label_course">
            <div class="modal-dialog" role="document">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                            <span aria-hidden="true">&times;</span>
                        </button>
                        <h4 class="modal-title" id="label_course"><strong>添加医院管理员</strong></h4>
                    </div>
                    <div class="modal-body">
                        <div class="row form-group">
                            <div class="col-md-3 control-label">
                                <label for="Name" class="pull-right">用户名</label>
                            </div>
                           
                            <div class="col-md-7 controls">
                                <input id="Name" class="form-control" type="text">
                            </div>
                        </div>
                       
                        <div class="row form-group">
                            <div class="col-md-3 control-label">
                                <label for="Address" class="pull-right">密码</label>
                            </div>
                            <div class="col-md-7 controls">
                                <input id="Password" class="form-control" type="password">
                            </div>                          
                        </div>
                        <div class="row form-group">
                            <div class="col-md-3 control-label">
                                <label for="Grade" class="pull-right">所属医院</label>
                            </div>
                            <div class="col-md-7 controls">
                                <select id="select_show" class="form-control">
                                    <option value="0" >请选择</option>
                                </select>
                            </div>
                        </div>
                    </div>
                    <div class="modal-footer">
                        <div id="doing" style="float:left;display:none;">
                            <i class="fa fa-circle-o-notch fa-spin"></i><span> 处理中...</span>
                        </div>
                        <div id="success" style="float: left; display: none; ">
                            <i class="fa fa-check-square"></i><span> 保存成功！</span>
                        </div>
                        <div id="error" style="float: left; display: none; ">
                            <i class="fa fa-warning"></i><span> 保存失败！</span>
                        </div>

                        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                        <button id="btn_add_hospital" type="button" class="btn btn-primary">提交</button>
                    </div>
                </div>
            </div>
        </div>
        <div class="col-md-10">
            <div class="page-header clearfix" style="padding:10px;">
                <h4 class="pull-left">医院管理员列表</h4>
                <!--操作按钮-->
                <div class="pull-right">
                    <a class="btn btn-success btn-sm" data-toggle="modal" data-target="#modal_add_user">添加医院管理员</a>
                </div>
            </div>

            <!--内容区域-->
            @*<form id="user-search-form" class="form-inline well well-sm" action="/Exam/QueryExam" method="post" novalidate="">
                    <div class="form-group">
                        <input type="text" id="keyword" name="ExamName" class="form-control" value="" placeholder="添加相关词">
                    </div>
                    <button class="btn btn-primary" type="submit">搜索</button>
                </form>*@

            <table id="user-table" class="table table-striped table-hover" data-search-form="#user-search-form">
                <thead>
                    <tr>
                        <td>编号</td>
                        <td>用户名</td>
                        <td>密码</td>
                        <td>医院名称</td>

                        @*<td>产品</td>*@
                        <td>操作</td>
                    </tr>
                </thead>
                <tbody id="mytbody">
                  

                </tbody>
            </table>

            <!--分页-->
            <nav class=" text-center">
                <ul id="pagination" class="pagination-sm"></ul>
            </nav>
        </div>
    </div>
</div>


@section Footer{
    <script type="text/javascript">
        $(function () {


            $('#pagination').twbsPagination({
                totalPages: '@ViewBag.TotalPage',
                visiblePages: 5,
                first: "首页",
                prev: "上一页",
                next: "下一页",
                last: "尾页",
                href: '/Admin/GetHospitalAdmin?pageIndex={{pageNumber}}',
                hrefVariable: '{{pageNumber}}'
            });




        });


    </script>
}


